using System;
using System.Data;
using System.Windows.Forms;

namespace VMExplorer.Controls
{
  public partial class DockPanel : UserControl
  {
    public DockPanel(Control ctrl, string title)
    {
      InitializeComponent();

      _container.Controls.Add(ctrl);
      _title.Text = title;

      Dock = DockStyle.Fill;
    }

    private void btnUndock_Click(object sender, EventArgs e)
    {
      Form undock = new DockableForm(_container.Controls[0],_title.Text);
      undock.Show();

      SplitterPanel currentPanel = (SplitterPanel)this.Parent;
      SplitContainer panelContainer = (SplitContainer)currentPanel.Parent;
      SplitterPanel siblingPanel = panelContainer.Panel1 == currentPanel ? panelContainer.Panel2 : panelContainer.Panel1;
      ControlCollection siblingControls = siblingPanel.Controls;
      
      Control panelParent = panelContainer.Parent;
      foreach(Control c in siblingPanel.Controls)
      {
        panelParent.Controls.Add(c);
      }
      panelParent.Controls.Remove(panelContainer);
    }
  }
}
